/*2S7LXljdWdGhrCxZ1MFl4nbo76lbmNV/zj9vAsZ4TsJjt35I/W4VBwuu/33I9fcb*/
// 固定资产盘点单列表
import React, { Component } from 'react';
import { createPage, base } from 'nc-lightapp-front';
import {
    CommitAction,
    buttonClick,
    initTemplate,
    searchBtnClick,
    pageInfoClick,
    doubleClick,
    rowSelected,
    setBatchBtnsEnable,
    afterEvent
} from './events';
import { pageConfig } from './const';
import ampub from 'ampub';
import ApproveDetail from 'uap/common/components/ApproveDetail';
import CreateNCUploade from 'uap/common/components/CreateNCUploade';

const { NCDiv } = base;
const { utils, components } = ampub;
const { multiLangUtils, listUtils } = utils;
const { createListTitleArea, getTitleName, creatListSocket } = listUtils;
const { getMultiLangByID } = multiLangUtils;
const { ApprovalTrans } = components;
const { createNCUploader } = CreateNCUploade;
const { searchAreaId, tableId, dataSource, pkField, pagecode, bill_type } = pageConfig;
class List extends Component {

    constructor(props) {
        super(props);
        props.use.search(searchAreaId);
        props.use.table(tableId);
        this.state = {
            /* 审批详情 */
            pk_evaluate: '',
            showApprove: false,
            bill_type: '',
            /* 打印 */
            printData: {},
            /* 提交指派 */
            compositedisplay: false,
            compositedata: {},
            uploader: {}
        };
        initTemplate.call(this, props);
    }

    componentDidMount() {}

    // 提交及指派 回调
    getAssginUsedr = (value) => {
        CommitAction.call(this, 'SAVE', this.props, value);
    };

    // 取消 指派
    turnOff = () => {
        this.setState({ compositedisplay: false });
    };

    render() {
        const { table, button, ncmodal, search } = this.props;
        const { createButtonApp } = button;
        const { createModal } = ncmodal;
        const { createSimpleTable } = table;
        const { NCCreateSearch } = search;

        return (
            <div className="nc-bill-list">
                <NCDiv areaCode={NCDiv.config.HEADER} className="nc-bill-header-area">
                    {/* 标题 title */}
                    <div className="header-title-search-area">
                        {createListTitleArea.call(this, this.props, { title: getTitleName.call(this, this.props) })}
                    </div>
                    {/* 按钮区 btn-area */}
                    <div className="header-button-area">
                        {createButtonApp({
                            area: 'list_head',
                            buttonLimit: 3,
                            onButtonClick: buttonClick.bind(this),
                            popContainer: document.querySelector('.header-button-area')
                        })}
                    </div>
                </NCDiv>
                <div className="nc-bill-search-area">
                    {NCCreateSearch(searchAreaId, {
                        onAfterEvent: afterEvent.bind(this),
                        clickSearchBtn: searchBtnClick.bind(this),
                        dataSource,
                        componentInitFinished: () => {
                            // 缓存数据赋值成功的钩子函数
                            // 若初始化数据后需要对数据做修改，可以在这里处理
                        }
                    })}
                </div>
                <div className="nc-bill-table-area">
                    {createSimpleTable(tableId, {
                        showCheck: true,
                        showIndex: true,
                        handlePageInfoChange: pageInfoClick.bind(this),
                        onRowDoubleClick: doubleClick.bind(this),
                        onSelected: rowSelected.bind(this),
                        onSelectedAll: rowSelected.bind(this),
                        dataSource,
                        pkname: pkField,
                        componentInitFinished: () => {
                            // 缓存数据赋值成功的钩子函数
                            // 若初始化数据后需要对数据做修改，可以在这里处理
                            setBatchBtnsEnable.call(this, this.props, tableId);
                        }
                    })}
                </div>
                {/* 确认取消框 */}
                {createModal(`${pagecode}-confirm`, { color: 'warning' })}
                {/* 附件管理框 */}
                {createNCUploader.call(this, `${pagecode}-uploader`, {})}
                {/* 审批详情 */}
                <ApproveDetail
                    show={this.state.showApprove}
                    close={() => {
                        this.setState({ showApprove: false });
                    }}
                    billtype={this.state.transi_type}
                    billid={this.state.pk_inventory}
                />
                {/* 提交及指派 */}
                {this.state.compositedisplay ? (
                    <ApprovalTrans
                        title={getMultiLangByID('amcommon-000002') /* 指派*/}
                        data={this.state.compositedata}
                        display={this.state.compositedisplay}
                        getResult={this.getAssginUsedr}
                        cancel={this.turnOff}
                    />
                ) : (
                    ''
                )}

                {/* 创建 socket 链接 */}
                {creatListSocket(this.props, {
                    tableAreaCode: tableId, // 表格区域编码
                    billpkname: pkField, // 表格主键
                    billtype: bill_type // 单据类型,用于查询追溯
                })}
            </div>
        );
    }

}

const MasterChildListBase = createPage({})(List);
export default MasterChildListBase;

/*2S7LXljdWdGhrCxZ1MFl4nbo76lbmNV/zj9vAsZ4TsJjt35I/W4VBwuu/33I9fcb*/